﻿@model Stertex.Models.ProfileRegistrationModel

@{
    ViewBag.Title = "Create new profile";
}

<h2>Create new profile</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<script type="text/javascript">
    $(document).ready(function () {
        $("#Email").change(function () {
            var a = $(this).val().split("@@")[0];
            var names = a.split(".");
            if(names.length ==2) {

                $("#Lastname").val(names[0]);
                $("#Firstname").val(names[1]);

            }

             var names = a.split("_");
            if(names.length ==2) {

                $("#Lastname").val(names[0]);
                $("#Firstname").val(names[1]);

            }

        });
        $("#Zip").change(function () {

            $.ajax({
                type: "POST",
                url: "@Url.Action("FindByZip","ZipCode")",
                data: "{ZipCode:'"+ $(this).val() +"'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    
                    $("#City").attr("value",msg.City);
                    $("#State").attr("value",msg.State);
                },
                error: function (e) {
                    // $(divToBeWorkedOn).html("Unavailable");
                }
            });

        });
    });
</script>
@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Profile details</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.Email)
        </div>
        <div class="editor-field">
            @Html.DisplayTextFor(model => model.Email)
            @Html.HiddenFor(model => model.Email)
            @Html.ValidationMessageFor(model => model.Email)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Lastname)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Lastname)
            @Html.ValidationMessageFor(model => model.Lastname)
        </div>
         <div class="editor-label">
            @Html.LabelFor(model => model.Firstname)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Firstname)
            @Html.ValidationMessageFor(model => model.Firstname)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Title)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Title)
            @Html.ValidationMessageFor(model => model.Title)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Company)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Company)
            @Html.ValidationMessageFor(model => model.Company)
        </div>
        
        <div class="editor-label">
            @Html.LabelFor(model => model.Address)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Address)
            @Html.ValidationMessageFor(model => model.Address)
        </div>
       
        <div class="editor-label">
            @Html.LabelFor(model => model.City)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.City)
            @Html.ValidationMessageFor(model => model.City)
        </div>


        <div class="editor-label">
            @Html.LabelFor(model => model.State)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.State)
            @Html.ValidationMessageFor(model => model.State)
        </div>

        
        <div class="editor-label">
            @Html.LabelFor(model => model.Zip)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Zip, new { maxlength = 5 })
            @Html.ValidationMessageFor(model => model.Zip)
        </div>

 <div class="editor-label">
            @Html.LabelFor(model => model.Phone)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Phone)
            @Html.ValidationMessageFor(model => model.Phone)
        </div>

       

        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to my Profile", "MyProfile")
</div>
